package space.misiro.ledgers.middleware.api.domain.um

import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import io.swagger.v3.oas.annotations.media.Schema

/**
 * 表示AIS（账户信息服务）账户访问信息的数据传输对象
 *
 * @property accounts 具有访问权限的账户IBAN列表，用于标识可操作的账户范围
 * @property balances 具有余额访问权限的账户IBAN列表，用于控制余额查询权限
 * @property transactions 具有交易记录访问权限的账户IBAN列表，用于控制交易历史查看权限
 * @property availableAccounts 表示对PSU（支付服务用户）所有可用账户的访问授权类型，ALL_ACCOUNTS表示全局授权
 * @property allPsd2 表示符合PSD2法规要求的全量访问授权类型，包含账户/余额/交易等所有权限的全局授权
 */
@JsonIgnoreProperties(ignoreUnknown = true)
@Schema(description = "Ais account access information", name = "AisAccountAccessInfo")
data class AisAccountAccessInfoTO(

    @field:Schema(description = "Access to accounts")
    var accounts: List<String> = emptyList(),

    @field:Schema(description = "Access to balances")
    val balances: List<String> = emptyList(),

    @field:Schema(description = "Access to transactions")
    var transactions: List<String> = emptyList(),

    @field:Schema(description = "Consent on all available accounts of psu", example = "ALL_ACCOUNTS")
    var availableAccounts: AisAccountAccessTypeTO = AisAccountAccessTypeTO.DEFAULT,

    @field:Schema(description = "Consent on all accounts, balances and transactions of psu", example = "ALL_ACCOUNTS")
    var allPsd2: AisAccountAccessTypeTO = AisAccountAccessTypeTO.DEFAULT
) {
    @get:JsonIgnore
    val listedAccountsIbans: Set<String>
        get() = listOf(accounts, balances, transactions).flatMapTo(mutableSetOf()) { it }
}
